import 'package:flutter/material.dart';

/// 选项数据，左右文字显示
class ItemOption extends StatelessWidget {
  final String? imagePath;
  final String text;
  final String? secondText;
  final Color? secondTextColor;
  final GestureTapCallback? onTap;
  final Widget? trailing;
  final bool? hideRightArrow;
  final bool? showTopBorder;
  final double? height;

  const ItemOption({
    Key? key,
    this.imagePath,
    required this.text,
    this.secondText,
    this.secondTextColor,
    this.onTap,
    this.trailing,
    this.hideRightArrow,
    this.height,
    this.showTopBorder,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    List<Widget> children = [
      Padding(
        padding:
            EdgeInsets.symmetric(horizontal: (imagePath == null) ? 0 : 18.0),
        child: Text(text),
      ),
      Expanded(
        child: Container(
          padding: const EdgeInsets.symmetric(horizontal: 8.0),
          child: Text(
            secondText ?? '',
            textAlign: TextAlign.end,
            overflow: TextOverflow.ellipsis,
            style: TextStyle(color: secondTextColor ?? Colors.grey),
          ),
        ),
      ),
    ];
    if (trailing != null) {
      children.add(trailing!);
    }
    children.add(
      Offstage(
        offstage: hideRightArrow ?? false,
        child: Image.asset(
          'assets/images/ic_arrow_right.png',
          width: 14,
          height: 14,
          color: Colors.grey,
        ),
      ),
    );
    if (imagePath != null) {
      children.insert(
          0,
          Image.asset(
            imagePath!,
            width: 22,
            color: Colors.grey[800],
          ));
    }
    return InkWell(
      child: Container(
        height: height ?? 60,
        decoration: BoxDecoration(
          color: Colors.white,
          border: Border(
              bottom: BorderSide(color: Colors.grey[200]!),
              top: showTopBorder ?? false
                  ? BorderSide(color: Colors.grey[200]!)
                  : BorderSide.none),
        ),
        padding: EdgeInsets.symmetric(horizontal: 16),
        child: Row(children: children),
      ),
      onTap: onTap,
    );
  }
}
